/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.cms.entity;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.jinhe.tss.cms.CMSConstants;
import com.jinhe.tss.component.dynproperty.support.AbstractDynEntity;
import com.jinhe.tss.component.recycle.Recycleable;
import com.jinhe.tss.core.util.BeanUtil;
import com.jinhe.tss.core.util.DateUtil;
import com.jinhe.tss.core.web.dispaly.grid.GridAttributesMap;
import com.jinhe.tss.core.web.dispaly.grid.IGridNode;
import com.jinhe.tss.core.web.dispaly.tree.ITreeNode;
import com.jinhe.tss.core.web.dispaly.tree.TreeAttributesMap;
import com.jinhe.tss.core.web.dispaly.xform.IXForm;

/** 
 * <p>文章Article实体对象</p>
 */
@Entity
@Table(name = "cms_article")
@SequenceGenerator(name = "article_sequence", sequenceName = "article_sequence", initialValue = 1, allocationSize = 10)
public class Article extends AbstractDynEntity implements ITreeNode, IGridNode, IXForm, Recycleable {
    
	public static final String[] IGNORE_PROPERTIES = new String[] { "id", "status", "hitCount", "issueDate" };
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "article_sequence")
    private Long   id;				//文章编号 PK
	
	@Column(nullable = false)
    private String title;			//标题  not-null
    private String subtitle;		//副标题
    private String keyword;			//关键字
    private String author;			//作者
    private String summary;			//摘要 
    private String rePrint;			//转载	转载自某站点某栏目   
    
    @Column(length = 4000, nullable = false)  
    private String  content;		//正文内容  Long  
    
    @Column(nullable = false)
    private Long articleTypeId;		//文章类型 not-null
    
    private Date    wzrq;           // 文章日期
    private Date    overdueDate;    // 过期时间
    private Date    issueDate;	    // 发布日期	开始为空,只有审核和发布阶段可以改
    private String  pubUrl;         // 发布路径
    
    private Integer hitCount   = new Integer(0);  //点击率
    private Integer scoreCount = new Integer(0);  //评分次数
    private Integer scores     = new Integer(0);  //总评分
	
    private Integer deleted = CMSConstants.FALSE; // 删除标志
    private Long    recycleId;                    // 回收站ID

    private Integer status = CMSConstants.START_STATUS;	   // 文章的状态 0: 锁定 1：编辑中 2：已编 3：已签 4：待发布 5：过期 -1：发布已生成xml
    private	Integer secret;			                       // 文章的秘级 0：普通（缺省）1：秘密 2：机密 3：绝密
    
    /* 临时添加，仅用于展示 */
    @Transient private String  typeName;       // 文章类型名称
    
    @Transient private Long    channelId;      // 文章所属栏目ID
    @Transient private String  channelName;    // 文章所属栏目名称
    @Transient private Channel site;           // 文章所在的站点
    @Transient private Integer articleOrigin;  // 文章来源 0：普通文章 1：分发文章 2：转载文章 3:导入文章 （取值于ChannelArticle）
    @Transient private Integer isTop;          // 文章是否置顶 （取值于ChannelArticle）
    @Transient private Integer seqNo;          // 栏目下文章的顺序 （取值于ChannelArticle）
    
    @Transient private Integer workflowId;     // 文章工作流ID
    @Transient private String  publishArticleClassName; //发布文章实现类
    
    @Transient Map<String, Attachment>  attachments = new LinkedHashMap<String, Attachment>();  //存放文章附件列表
    
 
    public Integer getArticleOrigin() {
        return articleOrigin;
    }
 
    public void setArticleOrigin(Integer articleOrigin) {
        this.articleOrigin = articleOrigin;
    }
 
    public String getAuthor() {
        return author;
    }
 
    public void setAuthor(String author) {
        this.author = author;
    }
 
    public String getContent() {
        return content;
    }
 
    public void setContent(String content) {
        this.content = content;
    }
 
    public Integer getDeleted() {
        return deleted;
    }
 
    public void setDeleted(Integer deleteTag) {
        this.deleted = deleteTag;
    }
 
    public Integer getHitCount() {
        return hitCount;
    }
 
    public void setHitCount(Integer hitCount) {
        this.hitCount = hitCount;
    }
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    public Date getIssueDate() {
        return issueDate;
    }
 
    public void setIssueDate(Date issueDate) {
        this.issueDate = issueDate;
    }
 
    public String getKeyword() {
        return keyword;
    }
 
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
 
    public String getRePrint() {
        return rePrint;
    }
 
    public void setRePrint(String rePrint) {
        this.rePrint = rePrint;
    }
 
    public Integer getSecret() {
        return secret;
    }
 
    public void setSecret(Integer secret) {
        this.secret = secret;
    }
 
    public Integer getStatus() {
        return status;
    }
 
    public void setStatus(Integer status) {
        this.status = status;
    }
 
    public String getSubtitle() {
        return subtitle;
    }
 
    public void setSubtitle(String subtitle) {
        this.subtitle = subtitle;
    }
 
    public String getSummary() {
        return summary;
    }
 
    public void setSummary(String summary) {
        this.summary = summary;
    }
 
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }
 
    public Long getArticleTypeId() {
        return articleTypeId;
    }
 
    public void setArticleTypeId(Long articleTypeId) {
        this.articleTypeId = articleTypeId;
    }
 
	public Date getWzrq() {
		return wzrq;
	}
 
	public void setWzrq(Date wzrq) {
		this.wzrq = wzrq;
	}
 
	public Long getRecycleId() {
		return recycleId;
	}
 
	public void setRecycleId(Long recycleId) {
		this.recycleId = recycleId;
	}
 
	public String getPubUrl() {
		return pubUrl;
	}
 
	public void setPubUrl(String pubUrl) {
		this.pubUrl = pubUrl;
	}
 
	public Integer getScoreCount() {
		return scoreCount;
	}
 
	public void setScoreCount(Integer scoreCount) {
		this.scoreCount = scoreCount;
	}
 
	public Integer getScores() {
		return scores;
	}
 
	public void setScores(Integer scores) {
		this.scores = scores;
	}
 
	public Date getOverdueDate() {
		return overdueDate;
	}
 
	public void setOverdueDate(Date overdueDate) {
		this.overdueDate = overdueDate;
	}
    
    public String getName(){
        return title;
    }
    
    public GridAttributesMap getAttributes(GridAttributesMap map) {
        Map<String, Object> attributes = new LinkedHashMap<String, Object>();
        BeanUtil.addBeanProperties2Map(this, attributes);
        map.putAll(attributes);
        
        if(CMSConstants.ARTICLE_DISTRIBUTE.equals(this.getArticleOrigin())) {
            map.put("icon", "../platform/images/icon/distribute_article.gif");
        } 
        else if(CMSConstants.ARTICLE_RESHIP.equals(this.getArticleOrigin())) {
            map.put("icon", "../platform/images/icon/reprint_article.gif");
        } 
        else if(CMSConstants.ARTICLE_FROMTHIRD.equals(this.getArticleOrigin())) {
            map.put("icon", "../platform/images/icon/import_article.gif");
        } 
        else {
            map.put("icon", "../platform/images/icon/article.gif");
        }
        
        return map;
    }

    public Map<String, Object> getAttributesForXForm() {
        Map<String, Object> map = new LinkedHashMap<String, Object>();
        BeanUtil.addBeanProperties2Map(this, map);
        map.put("id", id);
        
        map.put("createTime", DateUtil.format(createTime));
        if(wzrq != null) {
        	map.put("wzrq", DateUtil.format(wzrq));
        }
        if(overdueDate != null) {
        	map.put("overdueDate", DateUtil.format(overdueDate));
        }
        if(issueDate != null) {
        	map.put("issueDate", DateUtil.format(issueDate));
        }
        
        map.putAll(super.dynpropertiesMap);
        return map;
    }

    public TreeAttributesMap getAttributes() {
        TreeAttributesMap map = new TreeAttributesMap(id.toString(), title);
        map.put("state", articleOrigin);
        return map;
    }

    public String getEntityCode() {   
        return "article" + articleTypeId;
    }
    
    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public String getPublishArticleClassName() {
        return publishArticleClassName;
    }

    public void setPublishArticleClassName(String publishArticleClassName) {
        this.publishArticleClassName = publishArticleClassName;
    }
 
    public Map<String, Attachment> getAttachments() {
        return attachments;
    }
    
    public Long getChannelId() {
        return channelId;
    }

    public void setChannelId(Long channelId) {
        this.channelId = channelId;
    }
    
    public String getChannelName() {
        return channelName;
    }

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }
    
    public Integer getSeqNo() {
        return seqNo;
    }
 
    public void setSeqNo(Integer seqNo) {
        this.seqNo = seqNo;
    }
    
    public Integer getWorkflowId() {
        return workflowId;
    }

    public void setWorkflowId(Integer workflowId) {
        this.workflowId = workflowId;
    }
    
    public String toString(){
        return "(id:" + this.id + ", title:" + this.title + ")"; 
    }

    public Channel getSite() {
        return site;
    }

    public void setSite(Channel site) {
        this.site = site;
    }

    public Integer getIsTop() {
        return isTop;
    }

    public void setIsTop(Integer isTop) {
        this.isTop = isTop;
    }
}